import { Module } from '@nestjs/common'
import { APP_GUARD, APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core'
import * as path from 'path'
import { ConfigModule, ConfigService } from 'nestjs-config'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { TypeOrmModule } from '@nestjs/typeorm'
import { StaffModule } from './modules/staff/staff.module'
import { AccountModule } from './modules/account/account.module'
import { WorkStateModule } from './modules/work-state/work-state.module'
import { AdminModule } from './modules/admin/admin.module'
import { ApplyModule } from './modules/apply/apply.module'
import { AuthModule } from './modules/auth/auth.module'
import { AwardModule } from './modules/award/award.module'
import { AwardRuleModule } from './modules/award-rule/award-rule.module'
import { DepartmentModule } from './modules/department/department.module'
import { JobModule } from './modules/job/job.module'
import { LogModule } from './modules/log/log.module'
import { MenuModule } from './modules/menu/menu.module'
import { NoticeModule } from './modules/notice/notice.module'
import { RoleModule } from './modules/role/role.module'
import { SalaryModule } from './modules/salary/salary.module'
import { TransferModule } from './modules/transfer/transfer.module'
import { CalendarModule } from './modules/calendar/calendar.module'
import { AuthModule as AuthModules } from './auth/auth.module'
import { JwtAuthGuard } from './auth/guards/jwt-auth.guard'
import { RolesGuard } from './role/guards/roles.guard'
import { ChangeSalaryModule } from './modules/change-salary/change-salary.module'
import { ResponseInterceptor } from './interceptor/response.interceptor'
import { Log } from './modules/log/entities/log.entity'
import { Staff } from './modules/staff/entities/staff.entity'
import { HttpExceptionFilter } from './filter/http-exception.filter'
import { AllExceptionFilter } from './filter/any-exception.filter'
import { UploadModule } from './upload/upload.module'
import { ContractModule } from './modules/contract/contract.module'
@Module({
  imports: [
    //1.配置config目录
    ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}')),
    //2.读取配置，这里读取的是数据库配置
    TypeOrmModule.forRootAsync({
      useFactory: (config: ConfigService) => config.get('database'),
      inject: [ConfigService]
    }),
    TypeOrmModule.forFeature([Log, Staff]),
    AccountModule,
    ChangeSalaryModule,
    WorkStateModule,
    AccountModule,
    AdminModule,
    ApplyModule,
    AppModule,
    AuthModule,
    AwardModule,
    AwardRuleModule,
    DepartmentModule,
    JobModule,
    LogModule,
    MenuModule,
    NoticeModule,
    RoleModule,
    SalaryModule,
    StaffModule,
    TransferModule,
    WorkStateModule,
    AuthModules,
    UploadModule,
    CalendarModule,
    ContractModule
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_GUARD,
      useClass: RolesGuard
    },
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: ResponseInterceptor
    },
    {
      provide: APP_FILTER,
      useClass: HttpExceptionFilter
    },
    {
      provide: APP_FILTER,
      useClass: AllExceptionFilter
    }
  ]
})
export class AppModule {}
